39 #include "fsl_debug_console.h" 43 #include "clock_config.h" 46 #include "Driver_I2C.h" 47 #include "Driver_I2C_SDK2.h" 61 #include "event_groups.h" 82 static void read_task(
void *pvParameters);
92 ARM_DRIVER_I2C*
I2Cdrv = &I2C_S_DRIVER_BLOCKING;
95 BOARD_InitDebugConsole();
97 I2Cdrv->Initialize(NULL);
98 I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
110 xTaskCreate(
read_task,
"READ", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
111 xTaskCreate(
fusion_task,
"FUSION", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
114 vTaskStartScheduler();
122 portTickType lastWakeTime;
123 const portTickType frequency = 1;
124 lastWakeTime = xTaskGetTickCount();
128 vTaskDelayUntil(&lastWakeTime, frequency);
138 float motion_baseline[3] = {0.0, 0.0, 0.0};
140 static bool lastStationary;
141 uint32_t stationaryCount = 0;
162 if (!lastStationary) {
168 if (lastStationary) {
190 lastStationary = stationary;
void initSensorFusionGlobals(SensorFusionGlobals *sfg, StatusSubsystem *pStatusSubsystem, ControlSubsystem *pControlSubsystem)
utility function to insert default values in the top level structure
int8_t FXLS8952_Read(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
void vApplicationIdleHook(void)
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
clearFIFOs_t * clearFIFOs
clear sensor FIFOs
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
Lower level sensor fusion interface.
int main(void)
This is a FreeRTOS (dual task) implementation of the NXP sensor fusion demo build.
bool motionCheck(float sample[3], float baseline[3], float tolerance, uint32_t winLength, uint32_t *count)
The motionCheck() function is not a sensor fusion function. It is a function that simply monitors an ...
void initializeStatusSubsystem(StatusSubsystem *pStatus)
initializeStatusSubsystem() should be called once at startup to initialize the data structure and to ...
The top level fusion structure.
streamData_t * stream
function to create packets for serial stream
EventGroupHandle_t event_group
installSensor_t * installSensor
function for installing a new sensor into t
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
StatusSubsystem() provides an object-like interface for communicating status to the user...
void vApplicationTickHook(void)
readSensors_t * readSensors
read all physical sensors
struct ControlSubsystem * pControlSubsystem
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
PhysicalSensor sensors[3]
This implementation uses three physical sensors.
updateStatus_t * updateStatus
status=next status
int8_t FXAS21002_Read(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
The sensor_fusion.h file implements the top level programming interface.
int8_t MAG3110_Read(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
Running in reduced power mode.
Provides function prototypes for driver level interfaces.
he ControlSubsystem encapsulates command and data streaming functions.
uint8_t sUARTOutputBuffer[256]
main output buffer defined in control.c
static void fusion_task(void *pvParameters)
ControlSubsystem controlSubsystem
used for serial communications
int8_t initializeControlPort(ControlSubsystem *pComm)
Initialize the control subsystem and all related hardware.
runFusion_t * runFusion
run the fusion routines
int8_t FXLS8952_Init(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
ARM_DRIVER_I2C * I2Cdrv
KSDK handle for the I2C port defined in Driver_I2C_KSDK2.c.
int8_t FXAS21002_Idle(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
Non-recoverable FAULT = something went very wrong.
Application-specific status subsystem.
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
int8_t MAG3110_Init(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
setStatus_t * queueStatus
queue status change for next regular interval
Defines control sub-system.
int8_t MAG3110_Idle(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
setStatus_t * setStatus
change status indicator immediately
static void read_task(void *pvParameters)
applyPerturbation_t * applyPerturbation
apply step function for testing purposes
int8_t FXAS21002_Init(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
StatusSubsystem statusSubsystem
provides visual (usually LED) status indicator